package com.jxb.broker.store;

import java.util.concurrent.CompletableFuture;

public class Test {
    static CompletableFuture<PutMessageStatus> flushOKFuture = new CompletableFuture<>();
    public static void main(String[] args) {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                wakeupCustomer(PutMessageStatus.PUT_OK);
            }
        });
        thread.start();
        Test test = new Test();
        CompletableFuture<PutMessageStatus> future = test.future();
        CompletableFuture<PutMessageStatus> combine = future.thenCombine(new CompletableFuture<>(), (flushStatus, replicaStatus) -> {
            System.out.println(flushStatus+"111111111111111222222222222222222");
            return flushStatus;
        });
        combine.thenAccept((res) -> {
            System.out.println(res + "结果。。。。。。。。。。。。");
        });
        System.out.println("1111111");
    }

    public static void wakeupCustomer(final PutMessageStatus putMessageStatus) {
        flushOKFuture.complete(putMessageStatus);
    }

    public CompletableFuture<PutMessageStatus> future() {
        return flushOKFuture;
    }
}
